<template>
	<view>
		<view class="item" style="padding: 20rpx 30rpx 0; margin-top: 20rpx">
			<u-form :model="model" ref="uform" label-width="auto">
				<view style="height: 50rpx; display: flex; align-items: center">
					<u-icon
						name="order"
						color="#1573FF"
						:label="1 == returnCarType ? '换车信息' : '退车信息'"
						label-color="#333333"></u-icon>
				</view>

				<u-form-item
					label="退车时间"
					v-if="viewStateBean.carBackTime[0]"
					:required="viewStateBean.carBackTime[2]"
					borderBottom
					@click="viewStateBean.carBackTime[1] && showTime(2)">
					<u-input
						v-model="model.carBackTime"
						inputAlign="right"
						placeholder="请选择时间"
						disabled
						disabledColor="#ffffff"
						border="none"></u-input>

					<view slot="right">
						<u-icon v-if="viewStateBean.carBackTime[1]" name="arrow-right"></u-icon>
					</view>
				</u-form-item>

				<u-form-item
					label="换车退车时间"
					v-if="viewStateBean.timeApply[0]"
					:required="viewStateBean.timeApply[2]"
					borderBottom
					@click="viewStateBean.timeApply[1] && showTime(1)">
					<u-input
						v-model="model.timeApply"
						inputAlign="right"
						placeholder="请选择时间"
						disabled
						disabledColor="#ffffff"
						border="none"></u-input>

					<view slot="right">
						<u-icon v-if="viewStateBean.timeApply[1]" name="arrow-right"></u-icon>
					</view>
				</u-form-item>

				<u-form-item
					label="退车类别"
					v-if="viewStateBean.carType[0]"
					:required="viewStateBean.carType[2]"
					borderBottom
					@click="viewStateBean.carType[1] && typeClick()">
					<u-input
						v-model="model.carTypeStr"
						inputAlign="right"
						placeholder="请选择类别"
						disabled
						disabledColor="#ffffff"
						border="none"></u-input>

					<view slot="right">
						<u-icon v-if="viewStateBean.carType[1]" name="arrow-right"></u-icon>
					</view>
				</u-form-item>

				<u-form-item
					label="退车里程数"
					v-if="viewStateBean.alterationMileage[0]"
					:required="viewStateBean.alterationMileage[2]"
					borderBottom>
					<u-input
						v-model="model.alterationMileage"
						inputAlign="right"
						type="digit"
						:disabled="!viewStateBean.alterationMileage[1]"
						disabledColor="#ffffff"
						border="none"
						placeholder="请输入退车里程数"></u-input>
				</u-form-item>

				<u-form-item
					v-if="viewStateBean.alterationType[0]"
					:required="viewStateBean.alterationType[2]"
					label="换车原因"
					borderBottom>
					<u-input
						v-model="model.alterationType"
						inputAlign="right"
						:disabled="!viewStateBean.alterationType[1]"
						disabledColor="#ffffff"
						border="none"
						placeholder="请输入原因"></u-input>
				</u-form-item>

				<u-form-item
					v-if="viewStateBean.alterationDesc[0]"
					:required="viewStateBean.alterationDesc[2]"
					label="退车原因"
					borderBottom>
					<u-input
						v-model="model.alterationDesc"
						inputAlign="right"
						:disabled="!viewStateBean.alterationDesc[1]"
						disabledColor="#ffffff"
						border="none"
						placeholder="请输入原因"></u-input>
				</u-form-item>

				<u-form-item
					label="车辆退回仓库"
					v-if="viewStateBean.depot[0]"
					:required="viewStateBean.depot[2]"
					borderBottom
					@click="viewStateBean.depot[1] && warehouseClick()">
					<u-input
						v-model="model.depot"
						inputAlign="right"
						disabled
						disabledColor="#ffffff"
						border="none"
						placeholder="请选择退回仓库"></u-input>

					<view slot="right">
						<u-icon v-if="viewStateBean.depot[1]" name="arrow-right"></u-icon>
					</view>
				</u-form-item>

				<u-form-item
					label="更改车辆状态"
					v-if="viewStateBean.shipType[0]"
					:required="viewStateBean.shipType[2]"
					borderBottom
					@click="viewStateBean.shipType[1] && shipTypeClick()">
					<u-input
						v-model="model.shipTypeName"
						inputAlign="right"
						disabled
						disabledColor="#ffffff"
						border="none"
						placeholder="请选择车辆状态"></u-input>

					<view slot="right">
						<u-icon v-if="viewStateBean.shipType[1]" name="arrow-right"></u-icon>
					</view>
				</u-form-item>

				<u-form-item
					label="退款时间"
					v-if="viewStateBean.refundTime[0]"
					:required="viewStateBean.refundTime[2]"
					borderBottom
					@click="viewStateBean.refundTime[1] && refundShow(2)">
					<u-input
						v-model="model.refundTime"
						inputAlign="right"
						placeholder="请选择时间"
						disabled
						disabledColor="#ffffff"
						border="none"></u-input>
					<view slot="right">
						<u-icon v-if="viewStateBean.refundTime[1]" name="arrow-right"></u-icon>
					</view>
				</u-form-item>
				<view v-for="(val, key, i) in model.feeItemConfig" :key="i" v-if="!val.hide">
					<view
						style="
							height: 50rpx;
							display: flex;
							align-items: center;
							padding: 10px 0px;
							border-bottom: 1px solid #e3e6ec;
						">
						<u-icon
							name="order"
							color="#1573FF"
							:label="val.fieldName"
							label-color="#333333"></u-icon>
					</view>
					<u-form-item
						v-for="(item, k, index) in val.feeItemConfig"
						:key="k"
						:label="item.serviceName"
						:required="val.edit && item.valRequired"
						borderBottom>
						<template #labelRight v-if="item.serviceName == '车辆租金欠款金额'">
							<view @click="tip" style="padding-left: 5rpx">
								<u-icon size="18" name="info-circle-fill"></u-icon>
							</view>
						</template>
						<u-input
							v-if="item.serviceProperty == 1 || item.serviceProperty == 2"
							:ref="k"
							v-model="model.feeItemConfig[key]['feeItemConfig'][k].value"
							inputAlign="right"
							:type="
								'bankName' == item.serviceField ||
								'payType' == item.serviceField ||
								'refundAccountName' == item.serviceField ||
								'feeDesc' == item.serviceField
									? 'text'
									: 'digit'
							"
							:disabled="!val.edit"
							maxlength="10"
							disabledColor="#ffffff"
							border="none"
							placeholder="请输入"
							@input="inputBlur"></u-input>
						<u-input
							v-else
							v-model="model.feeItemConfig[key]['feeItemConfig'][k].value"
							inputAlign="right"
							type="text"
							:disabled="!val.edit"
							maxlength="200"
							disabledColor="#ffffff"
							border="none"
							placeholder="请输入"
							@input="inputBlur"></u-input>
					</u-form-item>
				</view>
				<!-- <u-form-item label="可退车辆保证金" v-if="viewStateBean.margin[0]" :required="viewStateBean.margin[2]" borderBottom>
					<u-input v-model="model.margin" inputAlign="right" type="digit" :disabled="!viewStateBean.margin[1]"
						disabledColor="#ffffff" border="none" placeholder="自动获取">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆违章分数" v-if="viewStateBean.illegalScore[0]" :required="viewStateBean.illegalScore[2]" borderBottom>
					<u-input v-model="model.illegalScore" inputAlign="right" type="number" :disabled="!viewStateBean.illegalScore[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入车辆违章分数">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆违章费用/元" v-if="viewStateBean.illegalAmount[0]" :required="viewStateBean.illegalAmount[2]" borderBottom>
					<u-input v-model="model.illegalAmount" inputAlign="right" type="digit" :disabled="!viewStateBean.illegalAmount[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入车辆违章费用">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆出险次数" v-if="viewStateBean.dangerCount[0]" :required="viewStateBean.dangerCount[2]" borderBottom>
					<u-input v-model="model.dangerCount" inputAlign="right" type="number" :disabled="!viewStateBean.dangerCount[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入车辆出险次数">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆出险费用/元" v-if="viewStateBean.dangerAmount[0]" :required="viewStateBean.dangerAmount[2]" borderBottom>
					<u-input v-model="model.dangerAmount" inputAlign="right" type="digit" :disabled="!viewStateBean.dangerAmount[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入车辆出险费用">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆定损实际定损金额/元" v-if="viewStateBean.actualAmount[0]" :required="viewStateBean.actualAmount[2]" borderBottom>
					<u-input v-model="model.actualAmount" inputAlign="right" type="digit" :disabled="!viewStateBean.actualAmount[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入车辆定损实际金额">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆可抵扣金额/元" v-if="viewStateBean.deductionAmount[0]" :required="viewStateBean.deductionAmount[2]" borderBottom>
					<u-input v-model="model.deductionAmount" inputAlign="right" type="digit" :disabled="!viewStateBean.deductionAmount[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入车辆可抵扣金额">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆租金欠款金额/元" v-if="viewStateBean.rentAmount[0]" :required="viewStateBean.rentAmount[2]" borderBottom>
					<u-input v-model="model.rentAmount" inputAlign="right" type="digit" :disabled="!viewStateBean.rentAmount[1]"
						disabledColor="#ffffff" border="none" placeholder="自动带出">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆违约金额/元" v-if="viewStateBean.defaultAmount[0]" :required="viewStateBean.defaultAmount[2]" borderBottom>
					<u-input v-model="model.defaultAmount" inputAlign="right" type="digit" :disabled="!viewStateBean.defaultAmount[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入车辆违约金额">
					</u-input>
				</u-form-item>

				<u-form-item label="车辆其它欠款金额/元" v-if="viewStateBean.otherAmount[0]" :required="viewStateBean.otherAmount[2]" borderBottom>
					<u-input v-model="model.otherAmount" inputAlign="right" type="digit" :disabled="!viewStateBean.otherAmount[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入车辆其他欠款金额">
					</u-input>
				</u-form-item>

				<u-form-item label="保养扣款" v-if="viewStateBean.maintenanceReduce[0]" :required="viewStateBean.maintenanceReduce[2]" borderBottom>
					<u-input v-model="model.maintenanceReduce" inputAlign="right" type="digit" :disabled="!viewStateBean.maintenanceReduce[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入保养扣款">
					</u-input>
				</u-form-item>

				<u-form-item label="洗车扣款" v-if="viewStateBean.washCarReduce[0]" :required="viewStateBean.washCarReduce[2]" borderBottom>
					<u-input v-model="model.washCarReduce" inputAlign="right" type="digit" :disabled="!viewStateBean.washCarReduce[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入洗车扣款">
					</u-input>
				</u-form-item>

				<u-form-item label="来年保险费增加费用/元" v-if="viewStateBean.addInsuranceFee[0]" :required="viewStateBean.addInsuranceFee[2]" borderBottom>
					<u-input v-model="model.addInsuranceFee" inputAlign="right" type="digit" :disabled="!viewStateBean.addInsuranceFee[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入来年保险费用增加费用">
					</u-input>
				</u-form-item>

				<u-form-item label="收车费用/元" v-if="viewStateBean.collectFee[0]" :required="viewStateBean.collectFee[2]" borderBottom>
					<u-input v-model="model.collectFee" inputAlign="right" type="digit" :disabled="!viewStateBean.collectFee[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入收车费用">
					</u-input>
				</u-form-item>

				<u-form-item label="转账手续费/元" v-if="viewStateBean.transferCommission[0]" :required="viewStateBean.transferCommission[2]" borderBottom>
					<u-input v-model="model.transferCommission" inputAlign="right" type="digit" :disabled="!viewStateBean.transferCommission[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入转账手续费">
					</u-input>
				</u-form-item>

				<u-form-item label="支付方式" v-if="viewStateBean.payType[0]" :required="viewStateBean.payType[2]" borderBottom>
					<u-input v-model="model.payType" inputAlign="right" type="digit" :disabled="!viewStateBean.payType[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入支付方式">
					</u-input>
				</u-form-item>

				<u-form-item label="退款账户名" v-if="viewStateBean.refundAccountName[0]" :required="viewStateBean.refundAccountName[2]" borderBottom>
					<u-input v-model="model.refundAccountName" inputAlign="right" type="digit" :disabled="!viewStateBean.refundAccountName[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入退款账户名">
					</u-input>
				</u-form-item>

				<u-form-item label="银行账号" v-if="viewStateBean.bankAccount[0]" :required="viewStateBean.bankAccount[2]" borderBottom>
					<u-input v-model="model.bankAccount" inputAlign="right" type="digit" :disabled="!viewStateBean.bankAccount[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入银行账号">
					</u-input>
				</u-form-item>

				<u-form-item label="开户行名称" v-if="viewStateBean.bankName[0]" :required="viewStateBean.bankName[2]" borderBottom>
					<u-input v-model="model.bankName" inputAlign="right" type="digit" :disabled="!viewStateBean.bankName[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入开户行名称">
					</u-input>
				</u-form-item>

				<u-form-item label="费用说明" v-if="viewStateBean.feeDesc[0]" :required="viewStateBean.feeDesc[2]" borderBottom>
					<u-input v-model="model.feeDesc" inputAlign="right" :disabled="!viewStateBean.feeDesc[1]"
						disabledColor="#ffffff" border="none" placeholder="请输入费用说明">
					</u-input>
				</u-form-item> -->

				<view
					v-if="viewStateBean.uploadAttach[0]"
					style="display: flex; flex-direction: column">
					<u-form-item
						:required="viewStateBean.uploadAttach[2]"
						label="上传凭证"></u-form-item>

					<lr-upload
						:disabled="!viewStateBean.uploadAttach[1]"
						ref="upload1"
						:objType="1 == returnCarType ? '13' : '14'"
						tag="1"
						@on-change="uploadOnChange"></lr-upload>
				</view>
			</u-form>
		</view>

		<view style="height: 180rpx"></view>
		<view class="tips" v-if="viewStateBean.settleAmount[0]">
			{{ newAmount < 0 ? '退还金额:' : '补缴金额:' }}￥{{ Math.abs(newAmount) }}
		</view>

		<view class="button-container">
			<button class="btn-item btn-right" @click="commit">确认</button>
		</view>

		<!-- 类型 -->
		<u-picker
			:mode="mode"
			:show="typeshow"
			:default-selector="[0]"
			:columns="rentTypeList"
			keyName="value"
			@confirm="typeConfirm"
			@cancel="typeshow = false"></u-picker>

		<!-- 车辆仓库 -->
		<u-picker
			:mode="mode"
			:show="carWarehouseShow"
			:default-selector="[0]"
			:columns="carWarehouseList"
			keyName="warehouseName"
			@confirm="warehouseConfirm"
			@cancel="carWarehouseShow = false"></u-picker>

		<!-- 车辆状态 -->
		<u-picker
			:mode="mode"
			:show="shipTypeShow"
			:default-selector="[0]"
			:columns="shipList"
			keyName="shipName"
			@confirm="shipTypeConfirm"
			@cancel="shipTypeShow = false"></u-picker>

		<!-- 时间 -->
		<u-datetime-picker
			:show="timeshow"
			:maxDate="maxDate"
			:minDate="minDate"
			mode="date"
			@confirm="timeConfirm"
			@cancel="timeshow = false"></u-datetime-picker>
		<!-- 退款时间 -->
		<u-datetime-picker
			:show="refundshow"
			mode="date"
			@confirm="refundConfirm"
			@cancel="refundshow = false"></u-datetime-picker>
		<u-modal :show="show" :closeOnClickOverlay="true" @confirm="closeTip" @close="closeTip">
			<view class="slot-content">
				<view>根据公司所设定的退租规则来计算退车租金，退车租金结算方式：</view>
				<div>1、按实际使用天数计算</div>
				<div>2、按原周期账单方式结算</div>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import lrUpload from '@/components/global/lr-upload.vue';
	var moment = require('@/common/moment.js');

	export default {
		components: {
			lrUpload,
		},
		data() {
			return {
				maxDate: moment().add(10, 'years').valueOf(),
				minDate: moment().add(-10, 'years').valueOf(),
				orderCarNo: '',
				returnCarType: '',
				rentType: '',
				orderCarId: '',
				instanceId: '',
				model: {
					uploadAttach: [],
					settleAmount: 0,
					repayType: 0,
					feeItemConfig: {},
				},
				carWarehouseList: [],
				shipList: [],
				rentTypeList: [],
				carWarehouseShow: false,
				shipTypeShow: false,
				timeshow: false,
				refundshow: false,
				typeshow: false,
				getData: false,
				newAmount: 0,
				viewStateBean: {
					carBackTime: [false, false, false],
					refundTime: [false, false, false],
					timeApply: [false, false, false],
					carType: [false, false, false],
					alterationMileage: [false, false, false],
					alterationType: [false, false, false],
					alterationDesc: [false, false, false],
					depot: [false, false, false],
					shipType: [false, false, false],
					margin: [false, false, false],
					illegalScore: [false, false, false],
					illegalAmount: [false, false, false],
					dangerCount: [false, false, false],
					dangerAmount: [false, false, false],
					actualAmount: [false, false, false],
					deductionAmount: [false, false, false],
					rentAmount: [false, false, false],
					defaultAmount: [false, false, false],
					otherAmount: [false, false, false],
					maintenanceReduce: [false, false, false],
					washCarReduce: [false, false, false],
					addInsuranceFee: [false, false, false],
					collectFee: [false, false, false],
					transferCommission: [false, false, false],
					payType: [false, false, false],
					refundAccountName: [false, false, false],
					bankAccount: [false, false, false],
					bankName: [false, false, false],
					feeDesc: [false, false, false],
					uploadAttach: [false, false, false],
					settleAmount: [false, false, false],
				},
				show: false,
			};
		},
		watch: {},
		computed: {},
		mounted() {
			let that = this;
			that.$nextTick(function () {
				setTimeout(() => {
					for (var key in that.model.feeItemConfig) {
						for (var k in that.model.feeItemConfig[key].feeItemConfig) {
							if (
								that.model.feeItemConfig[key].feeItemConfig[k].serviceProperty ===
									1 ||
								that.model.feeItemConfig[key].feeItemConfig[k].serviceProperty === 2
							) {
								that.$refs[k][0].setFormatter(e => {
									return e
										.replace(/[^\d.]/g, '')
										.replace(/\.{2,}/g, '.')
										.replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
								});
							}
						}
					}
				}, 1500);
			});
		},
		methods: {
			closeTip() {
				this.show = false;
			},
			tip() {
				this.show = true;
			},
			// 动态字段失去焦点变化
			inputBlur() {
				let that = this;
				let num = 0;
				for (var key in that.model.feeItemConfig) {
					for (var k in that.model.feeItemConfig[key].feeItemConfig) {
						if (that.model.feeItemConfig[key].feeItemConfig[k].serviceProperty === 1) {
							// num -= Number(that.model.feeItemConfig[key].feeItemConfig[k].value || 0)
							num = Number(num).sub(
								Number(that.model.feeItemConfig[key].feeItemConfig[k].value || 0),
							);
						} else if (
							that.model.feeItemConfig[key].feeItemConfig[k].serviceProperty === 2
						) {
							// console.log(that.model.feeItemConfig[key].feeItemConfig[k])
							num = Number(num).add(
								Number(that.model.feeItemConfig[key].feeItemConfig[k].value || 0),
							);
						} else {
						}
					}
				}
				console.log('str==>' + num);
				that.newAmount = num;
			},
			warehouseClick() {
				this.carWarehouseShow = true;
			},
			shipTypeClick() {
				this.shipTypeShow = true;
			},

			typeClick() {
				this.typeshow = true;
			},

			showTime(type) {
				this.timeshow = true;
			},
			refundShow(type) {
				this.refundshow = true;
			},
			timeConfirm(e) {
				let timeStr = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
				this.timeshow = false;
				if (1 == this.returnCarType) {
					this.model.timeApply = timeStr;

					this.$u.api
						.transferMonthlyRentDebt(
							this.orderCarNo,
							moment(this.model.timeApply).valueOf(),
						)
						.then(res => {
							console.log(this.model);

							// this.model.feeItemConfig.serviceConfig4.feeItemConfig.rentAmount.value = Number(res.monthlyRentDebt).toFixed(2)
							this.findAndSetOtherAmount(
								this.model,
								'rentAmount',
								this.formatNumber(res.monthlyRentDebt),
							);
							// this.model.rentAmount = Number(res.monthlyRentDebt).toFixed(2)
							console.log('this.model.rentAmount', this.model.rentAmount);
							// this.inputBlur()
							// this.$forceUpdate()
						});
				} else {
					this.model.carBackTime = timeStr;
				}
			},

			formatNumber(money) {
				return new Number(money || 0).toFixed(3).replace(/([0-9]+\.[0-9]{2})[0-9]*/, '$1');

				// if (str.includes(".")) {
				// 	let parts = str.split(".");
				// 	if (parts[1].length > 2) {
				// 		return parts[0] + "." + parts[1].substring(0, 2);
				// 	}{
				// 		return str;
				// 	}
				// }
				// return str;
			},
			findAndSetOtherAmount(obj, name, newValue) {
				let that = this;
				for (const key in obj) {
					if (obj.hasOwnProperty(key)) {
						if (key === name) {
							// 找到 otherAmount 并赋值
							if (typeof obj[key] === 'object') {
								obj[key].value = newValue;
								that.inputBlur();
								that.$forceUpdate();
							} else {
								obj[key] = newValue;
								that.inputBlur();
								that.$forceUpdate();
							}

							console.log('key', obj);
						} else if (typeof obj[key] === 'object' && obj[key] !== null) {
							// 递归遍历子对象
							this.findAndSetOtherAmount(obj[key], name, newValue);
						}
					}
				}
			},
			refundConfirm(e) {
				let timeStr = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
				this.refundshow = false;
				this.model.refundTime = timeStr;
			},

			typeConfirm(e) {
				this.typeshow = false;
				this.model.carType = e.value[0].code;
				this.model.carTypeStr = e.value[0].value;
			},

			warehouseConfirm(e) {
				this.carWarehouseShow = false;
				this.model.depotId = e.value[0].warehouseId;
				this.model.depot = e.value[0].warehouseName;
			},

			shipTypeConfirm(e) {
				this.shipTypeShow = false;
				this.model.shipType = e.value[0].shipValue;
				this.model.shipTypeName = e.value[0].shipName;
			},

			//图片上传成功回调
			uploadOnChange(tag, resultList, resultObjList) {
				console.log(tag, resultList, resultObjList);
				switch (tag) {
					case '1':
						this.model.uploadAttach = resultObjList;
						break;
				}
			},

			//提交
			commit() {
				let that = this;

				if (
					that.viewStateBean.carBackTime[2] &&
					uni.$u.test.isEmpty(that.model.carBackTime)
				) {
					this.$u.toast('请选择退车时间');
					return;
				}
				if (
					that.viewStateBean.refundTime[2] &&
					uni.$u.test.isEmpty(that.model.refundTime)
				) {
					this.$u.toast('请选择退款时间');
					return;
				}
				if (that.viewStateBean.timeApply[2] && uni.$u.test.isEmpty(that.model.timeApply)) {
					this.$u.toast('请选择换车退车时间');
					return;
				}

				if (that.viewStateBean.carType[2] && uni.$u.test.isEmpty(that.model.carType)) {
					this.$u.toast('请选择类别');
					return;
				}

				if (
					that.viewStateBean.alterationMileage[2] &&
					uni.$u.test.isEmpty(that.model.alterationMileage)
				) {
					this.$u.toast('请输入退车里程数');
					return;
				}

				if (
					that.viewStateBean.alterationType[2] &&
					uni.$u.test.isEmpty(that.model.alterationType)
				) {
					this.$u.toast('请输入换车原因');
					return;
				}

				if (
					that.viewStateBean.alterationDesc[2] &&
					uni.$u.test.isEmpty(that.model.alterationDesc)
				) {
					this.$u.toast('请输入退车原因');
					return;
				}

				if (that.viewStateBean.depot[2] && uni.$u.test.isEmpty(that.model.depot)) {
					this.$u.toast('请选择退回仓库');
					return;
				}

				if (that.viewStateBean.shipType[2] && uni.$u.test.isEmpty(that.model.shipType)) {
					this.$u.toast('请选择车辆状态');
					return;
				}

				if (that.viewStateBean.margin[2] && uni.$u.test.isEmpty(that.model.margin)) {
					this.$u.toast('请输入可退车辆保证金');
					return;
				}

				if (
					that.viewStateBean.illegalScore[2] &&
					uni.$u.test.isEmpty(that.model.illegalScore)
				) {
					this.$u.toast('请输入车辆违章分数');
					return;
				}

				if (
					that.viewStateBean.illegalAmount[2] &&
					uni.$u.test.isEmpty(that.model.illegalAmount)
				) {
					this.$u.toast('请输入车辆违章费用');
					return;
				}

				if (
					that.viewStateBean.dangerCount[2] &&
					uni.$u.test.isEmpty(that.model.dangerCount)
				) {
					this.$u.toast('请输入车辆出险次数');
					return;
				}

				if (
					that.viewStateBean.dangerAmount[2] &&
					uni.$u.test.isEmpty(that.model.dangerAmount)
				) {
					this.$u.toast('请输入车辆出险费用');
					return;
				}

				if (
					that.viewStateBean.actualAmount[2] &&
					uni.$u.test.isEmpty(that.model.actualAmount)
				) {
					this.$u.toast('请输入车辆定损实际金额');
					return;
				}

				if (
					that.viewStateBean.deductionAmount[2] &&
					uni.$u.test.isEmpty(that.model.deductionAmount)
				) {
					this.$u.toast('请输入车辆可抵扣金额');
					return;
				}

				if (
					that.viewStateBean.rentAmount[2] &&
					uni.$u.test.isEmpty(that.model.rentAmount)
				) {
					this.$u.toast('请输入车辆租金欠款金额');
					return;
				}

				if (
					that.viewStateBean.defaultAmount[2] &&
					uni.$u.test.isEmpty(that.model.defaultAmount)
				) {
					this.$u.toast('请输入车辆违约金额');
					return;
				}

				if (
					that.viewStateBean.otherAmount[2] &&
					uni.$u.test.isEmpty(that.model.otherAmount)
				) {
					this.$u.toast('请输入车辆其他欠款金额');
					return;
				}

				if (
					that.viewStateBean.maintenanceReduce[2] &&
					uni.$u.test.isEmpty(that.model.maintenanceReduce)
				) {
					this.$u.toast('请输入保养扣款');
					return;
				}

				if (
					that.viewStateBean.washCarReduce[2] &&
					uni.$u.test.isEmpty(that.model.washCarReduce)
				) {
					this.$u.toast('请输入洗车扣款');
					return;
				}

				if (
					that.viewStateBean.addInsuranceFee[2] &&
					uni.$u.test.isEmpty(that.model.addInsuranceFee)
				) {
					this.$u.toast('请输入来年保险费用增加费用');
					return;
				}

				if (
					that.viewStateBean.collectFee[2] &&
					uni.$u.test.isEmpty(that.model.collectFee)
				) {
					this.$u.toast('请输入收车费用');
					return;
				}

				if (
					that.viewStateBean.transferCommission[2] &&
					uni.$u.test.isEmpty(that.model.transferCommission)
				) {
					this.$u.toast('请输入转账手续费');
					return;
				}

				if (that.viewStateBean.payType[2] && uni.$u.test.isEmpty(that.model.payType)) {
					this.$u.toast('请输入支付方式');
					return;
				}

				if (
					that.viewStateBean.refundAccountName[2] &&
					uni.$u.test.isEmpty(that.model.refundAccountName)
				) {
					this.$u.toast('请输入退款账户名');
					return;
				}

				if (
					that.viewStateBean.bankAccount[2] &&
					uni.$u.test.isEmpty(that.model.bankAccount)
				) {
					this.$u.toast('请输入银行账号');
					return;
				}

				if (that.viewStateBean.bankName[2] && uni.$u.test.isEmpty(that.model.bankName)) {
					this.$u.toast('请输入开户行名称');
					return;
				}

				if (that.viewStateBean.feeDesc[2] && uni.$u.test.isEmpty(that.model.feeDesc)) {
					this.$u.toast('请输入费用说明');
					return;
				}

				if (
					that.viewStateBean.uploadAttach[2] &&
					uni.$u.test.isEmpty(that.model.uploadAttach)
				) {
					this.$u.toast('请上传凭证');
					return;
				}

				for (const item in that.model.feeItemConfig) {
					let itemVal = that.model.feeItemConfig[item];
					for (const sitem in itemVal.feeItemConfig) {
						let sitemVal = itemVal.feeItemConfig[sitem];
						if (
							itemVal.edit &&
							sitemVal.valRequired &&
							(sitemVal.value == undefined ||
								sitemVal.value == null ||
								sitemVal.value == '')
						) {
							// that.$u.toast('请输入', sitemVal.serviceName)
							uni.showToast({
								title: `请输入${sitemVal.serviceName}`,
								icon: 'error',
							});
							console.log('请输入', sitemVal.serviceName);
							return false;
						}
					}
				}

				uni.showModal({
					content: '确定提交吗?',
					success(res) {
						if (res.confirm) {
							that.$u.api.applyforSave(that.model).then(res => {
								uni.$emit('refreshOrder', true);
								that.$u.toast('提交成功');
								setTimeout(() => {
									uni.navigateBack();
								}, 1000);
							});
						}
					},
				});
			},

			getOldData(typestr) {
				this.$u.api
					.orderActivitySavedata({
						processKey: typestr,
					})
					.then(res => {
						this.setViewState(res);
					});
			},

			setViewState(res) {
				let that = this;

				//处理动态数据
				if (!uni.$u.test.isEmpty(res.list)) {
					for (let module of res.list) {
						for (let field of module.fields) {
							that.viewStateBean[field.fieldInfo] = [
								!field.hide,
								field.edit,
								field.required,
							];
						}
					}
				}
				this.$forceUpdate();
			},
		},
		onLoad(op) {
			console.log('op', op);
			this.orderCarNo = 'null' != op.orderCarNo ? op.orderCarNo : '';
			this.returnCarType = 'null' != op.returnCarType ? op.returnCarType : '';
			this.rentType = 'null' != op.rentType ? op.rentType : '';
			this.orderCarId = 'null' != op.orderCarId ? op.orderCarId : '';
			this.instanceId = op.instanceId ? op.instanceId : 'getInstanceId';
			this.carWarehouseList = [this.$store.state.params.warehouseList];
			this.rentTypeList = [this.$store.state.params.getCarCommon.rentType];
			this.model.returnCarType = this.returnCarType;
			this.shipList = [
				[
					{
						shipName: '整备中',
						shipValue: '1',
					},
					{
						shipName: '备发车',
						shipValue: '2',
					},
				],
			];

			if (1 == this.returnCarType) {
				if (2 == this.rentType) {
					this.getOldData('rentSaleTransferCar');
					this.model.processKey = 'rentSaleTransferCar';
				} else {
					this.getOldData('rentTransferCar');
					this.model.processKey = 'rentTransferCar';
				}

				uni.setNavigationBarTitle({
					title: '申请换车',
				});

				this.$u.api
					.transferInfoByOrderCarId({
						orderCarId: this.orderCarId,
					})
					.then(res => {
						let { currTimeStartRent, timeStartRent, timeFinishRent } = res;

						this.maxDate = moment(timeFinishRent).valueOf();
						this.minDate = currTimeStartRent
							? moment(currTimeStartRent).valueOf()
							: moment(timeStartRent).valueOf();
					});
			} else if (2 == this.returnCarType) {
				if (2 == this.rentType) {
					this.getOldData('rentSaleApprove');
					this.model.processKey = 'rentSaleApprove';
				} else if (6 == this.rentType) {
					this.getOldData('purchaseBackApprove');
					this.model.processKey = 'purchaseBackApprove';
				} else {
					this.getOldData('carBackApprove');
					this.model.processKey = 'carBackApprove';
				}

				uni.setNavigationBarTitle({
					title: '申请退车',
				});
			}
			this.$u.api
				.getServiceConfig({
					rentType: this.rentType,
					orderCarId: this.orderCarId,
					suitType: this.returnCarType === '1' ? '2' : '1',
					instanceId: this.instanceId,
				})
				.then(res => {
					this.model.feeItemConfig = res;
					this.inputBlur();
				});

			this.$u.api
				.applyforShow({
					orderCarNo: op.orderCarNo,
				})
				.then(res => {
					this.getData = true;
					this.model.orderId = res.orderId;
					this.model.orderCarId = res.orderCarId;
					this.model.orderCarCode = res.orderCarCode;
					this.model.margin = res.margin;
					this.model.rentAmount = res.rentAmount;
				});
		},
	};
</script>

<style lang="scss" scoped>
	.r-content {
		display: flex;
		flex-direction: column;
	}

	.state {
		width: 100%;
		line-height: 118rpx;
		text-align: center;
		font-size: 45rpx;
		color: #ffc000;
		font-weight: bold;
		background-color: #fff;
	}

	.bottom-text {
		display: flex;
		align-items: flex-end;
		height: 50rpx;
		margin-right: 20rpx;
		justify-content: flex-end;
	}

	.tips {
		display: flex;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 100rpx;
		z-index: 998;
		background-color: #1573ff;
		height: 70rpx;
		color: #fff;
		font-size: 26rpx;
		line-height: 70rpx;
		justify-content: center;
	}
</style>
